#!/bin/sh

if [ -n "$1" ]; then
    data_date=$1
else
  data_date=$(date -d "-1 days" +%F)
fi

LOAD_DATE_DWD="
insert overwrite table xm1_dwd.dwd_event partition (dt='${data_date}')

select
account, appid, appversion, carrier, deviceid, devicetype, eventid, ip, latitude,
longitude, nettype, osname, osversion, properties, releasechannel, resolution,
new_session_id, \`timestamp\`,t2.province_name,t2.city_name,t2.district_name,t2.street_name
    from xm1_tmp.tmp_log_new_session t1 left join xm1_dim.dim_province t2
on cottt(latitude,longitude,6)=t2.geohash;"

/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e"${LOAD_DATE_DWD}"